package ywpt.service.config;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.CommonTable;
import ywpt.model.UnitInfo;
import ywpt.model.WeixinAccount;
import com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine;
import ywpt.web.common.PublicFunction;
@Service("respMsgInfoDefineService")
@RemoteProxy(name="respMsgInfoDefineService")
public class RespMsgInfoDefineServiceImpl extends HibernateEntityDao<RespMsgInfoDefine> implements RespMsgInfoDefineService {

	@Override
	public com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine getRespMsgInfoDefineById(
			Long id) {
		// TODO Auto-generated method stub
		return null;
	}
	@RemoteMethod
	@Override
	public List<com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine> getRespMsgInfoDefineByTitle(
			String title, Long wexinAccountId, int start, int size) {
		// TODO Auto-generated method stub
		DetachedCriteria query = DetachedCriteria.forClass(RespMsgInfoDefine.class);
		query.createAlias("weixinAccount", "weixinAccount").add(Restrictions.eq("weixinAccount.id", wexinAccountId));
		if ( title != null && !title.trim().equals("") )
		{
			query.add(Restrictions.like("title", "%" + title + "%"));
		}
		query.add(Restrictions.eq("delete_Flag", false));
		query.addOrder(Order.asc("id"));
		List<RespMsgInfoDefine> respMsgInfoDefineList = new ArrayList<RespMsgInfoDefine>();
		List<RespMsgInfoDefine> respMsgInfoDefineLists = new ArrayList<RespMsgInfoDefine>();
		RespMsgInfoDefine respMsgInfoDefine =new RespMsgInfoDefine();
		
		respMsgInfoDefineList.addAll(this.findAllByCriteria(query, size, start));
		int i = 1;
		for ( Iterator<RespMsgInfoDefine> itr = respMsgInfoDefineList.iterator(); itr.hasNext(); i++ ) 
		{
			respMsgInfoDefine = itr.next();
			String ss = PublicFunction.format(respMsgInfoDefine.getTitle() + "",10, "  ", 1); 
			
			respMsgInfoDefine.setTitle(ss);
			respMsgInfoDefineLists.add(respMsgInfoDefine);
		}
		System.out.println("respMsgInfoDefineLists.size = "+respMsgInfoDefineLists.size() );
		return respMsgInfoDefineLists;
	}
	@RemoteMethod
	@Override
	public int getRespMsgInfoDefineCountByTitle(String title, Long wexinAccountId) {
		// TODO Auto-generated method stub
		DetachedCriteria query = DetachedCriteria.forClass(RespMsgInfoDefine.class);
		query.createAlias("weixinAccount", "weixinAccount").add(Restrictions.eq("weixinAccount.id", wexinAccountId));
		if ( title != null && !title.trim().equals("") )
		{
			query.add(Restrictions.like("title", "%" + title + "%"));
		}
		query.add(Restrictions.eq("delete_Flag", false));
		query.setProjection(null);
		System.out.println("getRespMsgInfoDefineCountByTitle.size = "+getCountByCriteria(query) );
		return this.getCountByCriteria(query);
	}

	@Override
	public int getRespMsgInfoDefineCountByCriteria(DetachedCriteria query) {
		// TODO Auto-generated method stub
		
		return 0;
	}

	@Override
	public List<com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine> getRespMsgInfoDefines() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine> getRespMsgInfoDefines(
			DetachedCriteria query, int pageSize, int startIndex) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void removeRespMsgInfoDefine(Long id) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveRespMsgInfoDefine(
			com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine respMsgInfoDefine,
			Long msgType, Long weixinAccountId, Long unitId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void saveRespMsgInfoDefine(
			com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine respMsgInfoDefine) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateRespMsgInfoDefine(
			com.ifp.weixin.MessageMng.Message.resp.RespMsgInfoDefine respMsgInfoDefine,
			Long msgType, Long weixinAccountId, Long unitId) {
		// TODO Auto-generated method stub
		
	}

	
}
